param(
    [Parameter(Mandatory)]
    [string]$Message
)

$Root = Split-Path -Path $PSScriptRoot;

$Global:Max = 0
$Global:Version = "v0.1.0";

function Set-Version{
    param(
        [string]$Tag
    )
    $Tag = $Tag.Replace("v", "")

    $Arr = $Tag.Split(".") ;
    $Major = [int]$Arr[0];
    $Minor = [int]$Arr[1];
    $Build = [int]($Arr[$Arr.Length -1]);

    $Total = ( $Major * 1024 * 1024) + ($Minor * 1024) + $Build
    if ( $Total -gt $Global:Max ){
        $Global:Max = $Total;
        $Build = $Build + 1;
        $Global:Version = "v${Major}.${Minor}.${Build}";
    }
}

git tag --list | Foreach-Object { Set-Version $_ };

Write-Host "create bindata release"
&"${Root}\bin\go-bindata.exe" -pkg=gen -o ./gen/bindata.go "./asset/..."

git -C $Root add .

git -C $Root commit -m $Message

git -C $Root tag $Global:Version
git -C $Root push
git -C $Root push --tags


&"${Root}\cmd\copy-code.ps1" -Version "${Global:Version}"

Write-Host "reset debug asset"
&"${Root}\bin\go-bindata.exe" -debug -pkg=gen -o ./gen/bindata.go "./asset/..."
Write-Host $Global:Version;